/**
 ****************************************************************
 * @file iso15693.h
 *
 * @brief 
 *
 * @author 
 *
 * 
 ****************************************************************
 */

#ifndef ISO15693_H
#define ISO15693_H
#include"define.h"
						
#define	ISO15693_UID_LENGTH									0x08

#define ERROR_FLAG											BIT0	//RSP FLAG

#define SUB_CARRIER_FLAG									BIT0	
#define DATA_RATE_FLAG										BIT1
#define INVENTORY_FLAG										BIT2
#define PROTOCOL_EXTENSION_FLAG								BIT3

#define SELECT_FLAG											BIT4	//INVENTORY_FLAG = 0
#define ADDRESS_FLAG										BIT5
#define OPTION_FLAG											BIT6

#define AFI_FLAG											BIT4	//INVENTORY_FLAG = 1
#define NB_SLOTS_FLAG										BIT5
#define OPTION_FLAG											BIT6

#define	INVENTORY_CMD										0x01
#define	STAY_QUIET_CMD										0x02
#define READ_SINGLE_BLOCK_CMD 								0x20
#define	WRITE_SINGLE_BLOCK_CMD								0x21
#define LOCK_BLOCK_CMD										0x22
#define	READ_MULTIPLE_BLOCK_CMD								0x23
#define	WRITE_MULTIPLE_BLOCK_CMD 							0x24
#define	SELECT_CMD											0x25
#define	RESET_TO_READY_CMD									0x26
#define	WRITE_AFI_CMD										0x27
#define	LOCK_AFI_CMD										0x28
#define	WRITE_DSFID_CMD										0x29
#define	LOCK_DSFID_CMD										0x2A
#define	GET_SYSTEM_INFORMATION_CMD							0x2B
#define	GET_MULTTIPLE_BLOCK_SECURITY_STATUS_CMD	     		0x2C


#define ISO15693_INVENTORY_RSP_LEN							10U
#define ISO15693_STAY_QUIET_CMD_RSP_LEN						10U

#define	BIT(y)					 (1 << y)					
#define	mask_bit_number(x)		 BIT((x - 1) % 8)
#define	mask_byte_number(z)		 ((z - 1) / 8)
#define	bit_random(a)			 (a % 2)				

int pcd_send_eof(u8 *pRxBuffer, u16 *pRxLength);

int pcd_inventory(
				  u8  bFlag, 
				  u8  bAfi, 
				  u8 *pMask, 
				  u8  bMaskBitLength, 
				  u8 *pDsfid, 
				  u8 *pUid
				  );

int pcd_stay_quiet(u8 *pUid, u8 bFlag);

int pcd_reset_to_ready(u8 *pUid, u8 bFlag);

int pcd_read_single_block(
						 u8  *pUid,
						 u8   bFlag, 
						 u8   bBlockNum,  
						 u8  *pRxBuffer, 
						 u8  *pErr,
						 u16 *pRxLength
						 );

int pcd_write_single_block(
						   u8  *pUid,
						   u8	bFlag, 
						   u8	bBlockNum, 
						   u8  *pTxBuffer,
						   u8  *pErr,
						   u16	wTxLength
						   );

int pcd_lock_block(u8 *pUid, u8 bFlag, u8 bBlockNum, u8 *pErr);

int pcd_read_multiple_block(
							u8  *pUid, 
							u8  bFlag, 
							u8  bBlockNum, 
							u8  bNumBlocks, 
							u8  *pRxBuffer, 
							u8  *pErr, 
							u16 *pRxLength
							);

int pcd_write_multiple_block(
						 u8  *pUid,
						 u8   bFlag, 
						 u8   bBlockNum,
						 u8   bNumBlocks,
						 u8  *pTxBuffer,
						 u8  *pErr,
						 u16  wTxLength
						 );

int pcd_select(u8 *pUid, u8 bFlag, u8 *pErr);

int pcd_write_afi(u8 *pUid, u8 bFlag, u8 bAfi, u8 *pErr);

int pcd_lock_afi(u8 *pUid, u8 bFlag, u8 *pErr);

int pcd_write_dsfid(u8 *pUid, u8 bFlag, u8 bDsfid, u8 *pErr);

int pcd_lock_dsfid(u8 *pUid, u8 bFlag, u8 *pErr);

int pcd_get_system_information(
								u8  *pUid, 
								u8   bFlag, 
								u8  *pErr, 
								u8  *pRxBuffer, 
								u16 *pRxLength
								);

int pcd_get_multiple_block_security_status(
												u8  *pUid,
												u8   bFlag, 
												u8   bBlockNum,
												u8   bNumBlocks,
												u8  *pErr,
												u8  *pSecurityStatus, 
												u16 *pSecStaLength
												);

void pcd_set_15693_tmo(u8 time);


#endif
